/**
 * @ Author: luoqi
 * @ Create Time: 2025-06-29 20:00
 * @ Modified by: luoqi
 * @ Modified time: 2025-11-07 00:58
 * @ Description:
 */
#include "cli.h"

static QCliObj cli;

int cli_init(void)
{
    return qcli_init(&cli, kprintf);
}

int cli_exec(char c)
{
    return qcli_exec(&cli, c);
}

int cli_echo(char *args)
{
    return qcli_echo(&cli, args);
}

int cli_add(const char *name, QCliCallback callback, const char *usage)
{
    if(name == QNULL || callback == QNULL || usage == QNULL) {
        return -1;
    }

    QCliCmd *cmd = qmalloc(sizeof(QCliCmd));
    return qcli_add(&cli, cmd, name, callback, usage);
}

int cli_del(const char *name)
{
    if(name == QNULL) {
        return -1;
    }
    QCliCmd *cmd = qcli_find(&cli, name);
    if(cmd == QNULL) {
        return -1;
    }
    int retval = qcli_del(&cli, cmd);
    qfree(cmd);
    return retval;
}

int cli_help(QCliArgsTable *table, uint32_t sz)
{
    uint32_t n = sz / sizeof(QCliArgsTable);
    for(uint32_t i = 0; i < n; i++) {
        QSH(" -%s %s\r\n", table[i].name, table[i].usage);
    }
    return 0;
}

